package com.lagou.edu.message.mq.listener;

import com.lagou.edu.common.constant.MQConstant;
import com.lagou.edu.common.mq.dto.BaseMqDTO;
import com.lagou.edu.common.mq.listener.AbstractMqListener;
import com.lagou.edu.course.api.dto.CourseDTO;
import com.lagou.edu.message.api.dto.LessonStatusReleaseDTO;
import com.lagou.edu.message.api.dto.Message;
import com.lagou.edu.message.server.PushServer;
import com.lagou.edu.message.service.IMessageService;
import com.lagou.edu.message.service.impl.MessageServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = MQConstant.Topic.COURSE_STATUS_RELEASE, consumerGroup = "${rocketmq.producer.group}" + "_" + MQConstant.Topic.COURSE_STATUS_RELEASE)
public class CourseStatusReleaseListener extends AbstractMqListener<BaseMqDTO<CourseDTO>> implements RocketMQListener<BaseMqDTO<CourseDTO>>{

    @Autowired
    IMessageService messageService;
	
    @Override
    public void onMessage(BaseMqDTO<CourseDTO> data) {

        System.out.println(data.toString());

        String userId = data.getMessageId();

        Message message = new Message();
        message.setContent(data.getData().getCourseName());
        message.setUserId(Integer.valueOf(userId));
        PushServer.pushServer.push(message);
    }
}